def _impl(ctx):
    print("=======Target {} ======".format(ctx.label))
    print(ctx.attr.text)

    file = ctx.actions.declare_file(ctx.attr.output_file)
    # print(file)

    # 在bazel-bin/hello-world下会生成start.txt文件
    ctx.actions.write(
        content = ctx.attr.text,
        output  = file,
    )

    return DefaultInfo(
        files = depset([file]),
    )

generate_file = rule(
    implementation = _impl,
    attrs = {
        "text"        : attr.string(mandatory=True),
        "output_file" : attr.string(mandatory=True)
    },
)